
package jpoco.android;

import jpoco.client.*;
import android.content.Context;
import android.widget.*;

public class ProviderView extends LinearLayout
{
	private ClientSettings settings;
	private boolean expanded = false;
	private TextView tview;
	private String compactText;
	private String expandedText;
	
	public ProviderView(Context context, ClientSettings cs)
	{
		super(context);
	
		this.expanded = false;
		
		this.settings = cs;
		
		this.setOrientation(LinearLayout.VERTICAL);
		
		compactText = createCompact(cs);
		
		expandedText = createExpanded(cs);
		
		tview = new TextView(context);
		tview.setText(compactText);
		tview.setTypeface(AndroidApplication.getDefaultTypeface());
		tview.setTextSize(AndroidApplication.getDefaultFontSize());
		
		this.addView(tview);
		
	}

	public void toggle()
	{
		setExpanded(!isExpanded());
	}
	
	protected String createCompact(ClientSettings cs)
	{
		return cs.getProviderName();
	}
	
	protected String createExpanded(ClientSettings cs)
	{
		return cs.getProviderName();
	}
	
	public void setExpanded(boolean b)
	{
		if (this.expanded == b)
		{
			return;
		}
		
		this.expanded = b;
		
		if (this.expanded)
		{
			this.tview.setText(expandedText);
		}
		else
		{
			this.tview.setText(compactText);
		}
	}
	
	public boolean isExpanded()
	{
		return this.expanded;
	}
	
	public String getProviderName()
	{
		return this.settings.getProviderName();
	}
	
	public ClientSettings getClientSettings()
	{
		return this.settings;
	}
	
}
